package com.block.datapush.common.filter.impl;

import cn.hutool.core.util.StrUtil;
import com.block.common.service.LogFactory;
import com.block.datapush.common.enums.FilterErrorEnum;
import com.block.datapush.common.filter.IFilterHandlerService;
import com.block.datapush.common.model.param.FilterHandlerParam;
import com.block.datapush.common.model.result.FilterHandlerResult;
import com.block.db.entity.MemberExtInfo;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

@Service
public class FilterIdCardHandlerService implements IFilterHandlerService {

    private static Logger log = LogFactory.getPushLog();

    @Override
    public FilterHandlerResult handlerFilterLogic(FilterHandlerParam handlerParam, MemberExtInfo memberExtInfo) {

        String userValue = memberExtInfo.getIdCard();
        String filterValue = handlerParam.getIdCard();

        if (StrUtil.isEmpty(filterValue)){
            return FilterHandlerResult.success();
        }

        if (StrUtil.isNotEmpty(userValue) && userValue.startsWith(filterValue)){
            return FilterHandlerResult.success();
        }

        String message = StrUtil.format("【filter】{}【value】{}", filterValue, userValue);
        log.info("【机构条件判断】false【身份证前缀】{}", message);
        return FilterHandlerResult.error(FilterErrorEnum.IDCARD_ERROR, message);
    }
}
